/**
 @file sys_usw_dmps_db.h

 @date 2021-11-19

 @version v2.0

 The file contains all port channel resource manager related APIs of sys layer
*/

#ifndef _SYS_USW_DMPS_DB_H
#define _SYS_USW_DMPS_DB_H
#ifdef __cplusplus
extern "C" {
#endif

/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "sal.h"
#include "ctc_const.h"
#include "ctc_chip.h"
#include "ctc_debug.h"
#include "sys_usw_common.h"
#include "sys_usw_port_api.h"

/****************************************************************
*
* Defines and Macros
*
****************************************************************/
#define DMPS_MAX_PORT_NUM 512
#define DMPS_MAX_MAC_NUM 324
#define DMPS_MAX_SERDES_NUM 324
#define DMPS_MAX_PCS_NUM 324
#define DMPS_MAX_CHAN_NUM 512
#define DMPS_MAX_CORE_NUM  2
#define DMPS_MAX_NUM_PER_MODULE 16
#define DMPS_MAX(a,b) (((a) > (b)) ? (a) : (b))

#define DMPS_INVALID_VALUE_U8 0xff
#define DMPS_INVALID_VALUE_U16 0xffff
#define DMPS_INVALID_VALUE_U32 0xffffffff
    
#define DMPS_MAX_PORT_NUM_PER_CORE 192
#define DMPS_NW_CPU_NUM_PER_CORE 194
#define DMPS_MAX_MAC_NUM_PER_CORE 160
#define DMPS_MAX_SERDES_NUM_PER_CORE 160
#define DMPS_MAX_PCS_NUM_PER_CORE 160
#define DMPS_MAX_CHAN_NUM_PER_CORE 208
#define DMPS_MAX_NUM_CPUMAC_MAP 4

#define DMPS_PP_NUM_PER_CORE PP_NUM_PER_CORE

#define SYS_DMPS_DB_MSG_PRI_NUM_MAX 2

#define SYS_DMPS_DB_DBG_OUT(level, FMT, ...) \
    do { \
        CTC_DEBUG_OUT(dmps_db, dmps_db, DMPS_DB_SYS, level, FMT, ##__VA_ARGS__); \
    } while (0)
#define CTC_ERROR_RETURN_DMPS_DB_UNLOCK(op) \
    do { \
        int32 rv; \
        if ((rv = (op)) < 0) \
        { \
            SYS_DMPS_DB_UNLOCK(lchip); \
            return (rv); \
        } \
    } while (0)
#define SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(op, ret) \
    do { \
        if(op) \
        { \
            SYS_DMPS_DB_UNLOCK(lchip); \
            return ret; \
        } \
    } while (0)

enum sys_xpipe_alloc_e
{
    SYS_XPIPE_ALLOC_FULL,
    SYS_XPIPE_ALLOC_HIGH,
    SYS_XPIPE_ALLOC_LOW, 
    SYS_XPIPE_ALLOC_BUTT    
};
typedef enum sys_xpipe_alloc_e sys_xpipe_alloc_t;
#define CHAN_DIR_RX (1 << DMPS_RX)
#define CHAN_DIR_TX (1 << DMPS_TX)
#define CHAN_DIR_TXRX (CHAN_DIR_RX | CHAN_DIR_TX)
#define CHAN_DIR_IS_RX(dir_bmp) ((dir_bmp & CHAN_DIR_RX) ? TRUE : FALSE)
#define CHAN_DIR_IS_TX(dir_bmp) ((dir_bmp & CHAN_DIR_TX) ? TRUE : FALSE)
#define CHAN_DIR_IS_TXRX(dir_bmp) (CHAN_DIR_IS_RX(dir_bmp) && CHAN_DIR_IS_TX(dir_bmp))
#define CHAN_DIR_IS_ENABLE(dir_bmp, p_dir) ((dir_bmp & p_dir) ? TRUE : FALSE)

#define GET_CHAN_DB_BY_DIR(dir_bmp, chan_id, pro) ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN(chan_id).pro : DMPS_DB_CHAN_RX(chan_id).pro)
#define GET_CHAN_TYPE_BY_DIR(dir_bmp)     ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_TYPE_CHAN          : DMPS_DB_TYPE_CHAN_RX)
#define GET_CHAN_ID_BY_DIR(dir_bmp)       ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN_ID            : DMPS_DB_CHAN_RX_ID)
#define GET_OLD_CHAN_ID_BY_DIR(dir_bmp)   ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_OLD_CHAN_ID        : DMPS_DB_OLD_CHAN_RX_ID)
#define GET_CORE_ID_BY_DIR(dir_bmp)       ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN_CORE_ID       : DMPS_DB_CHAN_RX_CORE_ID)
#define GET_PP_ID_BY_DIR(dir_bmp)         ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN_PP_ID         : DMPS_DB_CHAN_RX_PP_ID)
#define GET_DP_ID_BY_DIR(dir_bmp)         ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN_DP_ID         : DMPS_DB_CHAN_RX_DP_ID)
#define GET_TXQM_ID_BY_DIR(dir_bmp)       ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN_TXQM_ID       : DMPS_DB_CHAN_RX_TXQM_ID)
#define GET_SUB_CHAN_ID_BY_DIR(dir_bmp)   ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN_SUB_CHAN_ID   : DMPS_DB_CHAN_RX_SUB_CHAN_ID)
#define GET_MAC_CLIENT_ID_BY_DIR(dir_bmp) ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN_MAC_CLIENT_ID : DMPS_DB_CHAN_RX_MAC_CLIENT_ID)
#define GET_SPEED_MODE_BY_DIR(dir_bmp)    ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN_SPEED_MODE    : DMPS_DB_CHAN_RX_SPEED_MODE)
#define GET_PRIO_BY_DIR(dir_bmp)          ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN_PRIO          : DMPS_DB_CHAN_RX_PRIO)
#define GET_IS_RSV_BY_DIR(dir_bmp)        ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN_IS_RSV        : DMPS_DB_CHAN_RX_IS_RSV)
#define GET_SPEED_VALUE_BY_DIR(dir_bmp)   ((CHAN_DIR_IS_TX(dir_bmp)) ? DMPS_DB_CHAN_SPEED_VALUE   : DMPS_DB_CHAN_RX_SPEED_VALUE)

enum sys_dmps_db_prop_e
{
    DMPS_DB_MAP,

    DMPS_DB_DPORT,
    DMPS_DB_CHAN_ID,
    DMPS_DB_CHAN_RX_ID,
    DMPS_DB_MAC_ID,
    DMPS_DB_PCS_ID,
    DMPS_DB_LOGIC_SERDES,
    DMPS_DB_PHYSIC_SERDES,

    DMPS_DB_OLD_DPORT,
    DMPS_DB_OLD_CHAN_ID,
    DMPS_DB_OLD_CHAN_RX_ID,
    DMPS_DB_OLD_MAC_ID,
    DMPS_DB_OLD_PCS_ID,
    DMPS_DB_OLD_LOGIC_SERDES,
    DMPS_DB_OLD_PHYSIC_SERDES,

    DMPS_DB_PORT_IDX,               /*sys_dmps_port_db_t.port_idx               uint8*/
    DMPS_DB_PORT_TYPE,              /*sys_dmps_port_db_t.port_type              uint8 sys_dmps_lport_type_t*/
    DMPS_DB_PORT_IF_TYPE,           /*sys_dmps_port_db_t.if_type                uint8 ctc_port_if_type_t*/
    DMPS_DB_PORT_IF_MODE,           /*sys_dmps_port_db_t.if_mode                uint8 ctc_chip_serdes_mode_t*/
    DMPS_DB_PORT_FEC_TYPE,          /*sys_dmps_port_db_t.fec_type               uint8 sys_port_fec_type_t*/
    DMPS_DB_PORT_AN_FEC,            /*sys_dmps_port_db_t.an_fec                 uint8 ctc_port_fec_type_t*/
    DMPS_DB_PORT_MDIO_MAP,          /*sys_dmps_port_db_t.mdio_map               uint8*/
    DMPS_DB_PORT_PHY_MAP,           /*sys_dmps_port_db_t.phy_map                uint8*/
    DMPS_DB_PORT_DEVNO_MAP,         /*sys_dmps_port_db_t.devno_map              uint8*/
    DMPS_DB_PORT_IS_RSV,            /*sys_dmps_port_db_t.is_rsv                 uint8*/
    DMPS_DB_PORT_AN_MODE,           /*sys_dmps_port_db_t.an_mode                uint8*/
    DMPS_DB_PORT_AN_EN,             /*sys_dmps_port_db_t.an_en                  uint32*/
    DMPS_DB_PORT_OLD_CL73_STAT,     /*sys_dmps_port_db_t.old_cl73_status        uint32*/
    DMPS_DB_PORT_LINK_INTR_EN,      /*sys_dmps_port_db_t.link_intr_en           uint32*/
    DMPS_DB_PORT_LINK_STATUS,       /*sys_dmps_port_db_t.link_status            uint32*/
    DMPS_DB_PORT_UNIDIR_EN,         /*sys_dmps_port_db_t.unidir_en              uint32*/
    DMPS_DB_PORT_RX_RST_HOLD,       /*sys_dmps_port_db_t.rx_rst_hold            uint32*/
    DMPS_DB_PORT_IS_CTLE_RUN,       /*sys_dmps_port_db_t.is_ctle_running        uint32*/
    DMPS_DB_PORT_XPIPE_EN,          /*sys_dmps_port_db_t.xpipe_en               uint32*/
    DMPS_DB_PORT_IS_AN_FIRST,       /*sys_dmps_port_db_t.is_an_first            uint32*/
    DMPS_DB_PORT_BP_ABILITY0,       /*sys_dmps_port_db_t.an_ability.base_ability0  uint32*/
    DMPS_DB_PORT_BP_ABILITY1,       /*sys_dmps_port_db_t.an_ability.base_ability1  uint32*/
    DMPS_DB_PORT_NP0_ABILITY0,      /*sys_dmps_port_db_t.an_ability.next0_ability0 uint32*/
    DMPS_DB_PORT_NP0_ABILITY1,      /*sys_dmps_port_db_t.an_ability.next0_ability1 uint32*/
    DMPS_DB_PORT_NP1_ABILITY0,      /*sys_dmps_port_db_t.an_ability.next1_ability0 uint32*/
    DMPS_DB_PORT_NP1_ABILITY1,      /*sys_dmps_port_db_t.an_ability.next1_ability1 uint32*/
    DMPS_DB_PORT_LINK_FSM,          /*sys_dmps_port_db_t.link_fsm               uint32*/
    DMPS_DB_PORT_LINK_MODE,         /*sys_dmps_port_db_t.link_mode              uint32*/

    DMPS_DB_CHAN_CORE_ID,           /*sys_dmps_chan_db_t.core_id                uint8*/
    DMPS_DB_CHAN_PP_ID,             /*sys_dmps_chan_db_t.pp_id                  uint8*/
    DMPS_DB_CHAN_DP_ID,             /*sys_dmps_chan_db_t.dp_id                  uint8*/
    DMPS_DB_CHAN_TXQM_ID,           /*sys_dmps_chan_db_t.txqm_id                uint8*/
    DMPS_DB_CHAN_SUB_CHAN_ID,       /*sys_dmps_chan_db_t.sub_chan_id            uint16*/
    DMPS_DB_CHAN_MAC_CLIENT_ID,     /*sys_dmps_chan_db_t.mac_client_id          uint16*/
    DMPS_DB_CHAN_SPEED_MODE,        /*sys_dmps_chan_db_t.speed_mode             uint8 sys_port_speed_t*/
    DMPS_DB_CHAN_IS_RSV,            /*sys_dmps_chan_db_t.is_rsv                 uint8*/
    DMPS_DB_CHAN_PRIO,              /*sys_dmps_chan_db_t.prio                   uint8*/
    DMPS_DB_CHAN_SPEED_VALUE,       /*sys_dmps_chan_db_t.speed_value            uint32*/

    DMPS_DB_CHAN_RX_CORE_ID,        /*sys_dmps_chan_rx_db_t.core_id             uint8*/
    DMPS_DB_CHAN_RX_PP_ID,          /*sys_dmps_chan_rx_db_t.pp_id               uint8*/
    DMPS_DB_CHAN_RX_DP_ID,          /*sys_dmps_chan_rx_db_t.dp_id               uint8*/
    DMPS_DB_CHAN_RX_TXQM_ID,        /*sys_dmps_chan_rx_db_t.txqm_id             uint8*/
    DMPS_DB_CHAN_RX_SUB_CHAN_ID,    /*sys_dmps_chan_rx_db_t.sub_chan_id         uint16*/
    DMPS_DB_CHAN_RX_MAC_CLIENT_ID,  /*sys_dmps_chan_rx_db_t.mac_client_id       uint16*/
    DMPS_DB_CHAN_RX_SPEED_MODE,     /*sys_dmps_chan_rx_db_t.speed_mode          uint8 sys_port_speed_t*/
    DMPS_DB_CHAN_RX_IS_RSV,         /*sys_dmps_chan_rx_db_t.is_rsv              uint8*/
    DMPS_DB_CHAN_RX_PRIO,           /*sys_dmps_chan_rx_db_t.prio                uint8*/
    DMPS_DB_CHAN_RX_SPEED_VALUE,    /*sys_dmps_chan_rx_db_t.speed_value         uint32*/

    DMPS_DB_MAC_SPEED,              /*sys_dmps_mac_db_t.mac_speed               uint8*/
    DMPS_DB_MAC_GROUP_ID,           /*sys_dmps_mac_db_t.mac_group_id            uint8*/
    DMPS_DB_MAC_IDX,                /*sys_dmps_mac_db_t.mac_idx                 uint8*/
    DMPS_DB_MAC_EN,                 /*sys_dmps_mac_db_t.en                      uint8*/

    DMPS_DB_PSD_PLL_SEL,            /*sys_dmps_psd_db_t.pll_sel     uint8*/
    DMPS_DB_PSD_RATE_DIV,           /*sys_dmps_psd_db_t.rate_div    uint8*/
    DMPS_DB_PSD_BIT_WIDTH,          /*sys_dmps_psd_db_t.bit_width   uint8*/
    DMPS_DB_PSD_RX_POLARITY,        /*sys_dmps_psd_db_t.rx_polarity uint8*/
    DMPS_DB_PSD_SUPPORT_SPEED,      /*sys_dmps_psd_db_t.support_speed uint32 sys_datapath_serdes_speed_t*/
    DMPS_DB_PSD_SPEED,              /*sys_dmps_psd_db_t.serdes_speed  uint32*/
    DMPS_DB_PSD_TX_POLARITY,        /*sys_dmps_psd_db_t.tx_polarity uint8*/
    DMPS_DB_PSD_OCS,                /*sys_dmps_psd_db_t.ocs         uint8 ctc_chip_serdes_ocs_mode_t*/
    DMPS_DB_PSD_LANE_ID,            /*sys_dmps_psd_db_t.physical_lane_id uint8*/
    DMPS_DB_PSD_IS_DYN,             /*sys_dmps_psd_db_t.is_dyn       uint8*/

    DMPS_DB_LSD_LANE_ID,            /*sys_dmps_lsd_db_t.logical_lane_id uint8*/
    DMPS_DB_LSD_PCSL_IDX,           /*sys_dmps_lsd_db_t.pcs_l_idx    uint8*/
    DMPS_DB_LSD_HSS_ID,             /*sys_dmps_lsd_db_t.hss_id       uint8*/

    DMPS_DB_PCS_IDX,                /*sys_dmps_pcs_db_t.pcs_idx                 uint8*/
    DMPS_DB_PCS_RX_RST_EN,          /*sys_dmps_pcs_db_t.rx_rst_en               uint8*/
    DMPS_DB_BUTT
};
typedef enum sys_dmps_db_prop_e sys_dmps_db_prop_t;

///////////////////////////////////////////////////////////////////////////////
struct sys_dmps_db_msg_mcu_info_s
{
    uint32 core_mcu_num;
    uint32 max_mcu_num;
    uint32 use_mcu_num;
    uint32 mcu_bmp[2];
};
typedef struct sys_dmps_db_msg_mcu_info_s sys_dmps_db_msg_mcu_info_t;

struct sys_dmps_db_msg_init_info_s
{
    uint32 header_len;
    uint32 priority_num;
    uint32 msg_id_num;
    uint32 buf_addr;
    uint32 sync_buf_len;
    uint32 async_buf_len;
    uint32 log_len;
    uint32 log_addr;
    int32 (*read)(uint8 lchip, uint8 mcu_id, uint32 addr, uint32 mask, uint32* p_value);
    int32 (*write)(uint8 lchip, uint8 mcu_id, uint32 addr, uint32 mask, uint32 value);
    int32 (*gen_intr)(uint8 lchip, uint8 mcu_id);
    int32 (*get_header_field)(void *p_header, uint8 field, uint32* p_val);
    int32 (*set_header_field)(void *p_header, uint8 field, uint32 val);
    sys_dmps_db_msg_mcu_info_t mcu_info;
};
typedef struct sys_dmps_db_msg_init_info_s sys_dmps_db_msg_init_info_t;

struct sys_dmps_db_msg_register_tab_s
{
    uint32 priority      :4;
    uint32 rps_data_size :8;
    uint32 resv          :20;
    int32 (*recv_cb)(uint8 lchip, uint8 mcu_id, uint32 msg_id, void *p_data, void *p_out);
};
typedef struct sys_dmps_db_msg_register_tab_s sys_dmps_db_msg_register_tab_t;

struct sys_dmps_db_msg_buf_s
{
    uint32 buf_len;
    uint32 cur_msg_id;
    uint32 msg_cnt;
    uint32 base_addr;
    uint32 send_ptr_addr;
    uint32 recv_ptr_addr;
};
typedef struct sys_dmps_db_msg_buf_s sys_dmps_db_msg_buf_t;

struct sys_dmps_db_msg_handle_s
{
    uint32                           header_len;
    uint32                           log_addr;
    uint32                           log_len;
    uint32                           sync_buf_addr;
    uint32                           sync_buf_len;
    uint32                           cur_sync_id;
    uint32                           priority_num :16;
    uint32                           msg_id_num   :16;
    sys_dmps_db_msg_buf_t            p_c2m_buf[SYS_DMPS_DB_MSG_PRI_NUM_MAX];
    sys_dmps_db_msg_buf_t            p_m2c_buf[SYS_DMPS_DB_MSG_PRI_NUM_MAX];
    sys_dmps_db_msg_mcu_info_t       mcu_info;
    sys_dmps_db_msg_register_tab_t   registers[SYS_DMPS_MSG_CODE_MAX];

    int32 (*read)(uint8 lchip, uint8 mcu_id, uint32 addr, uint32 mask, uint32* p_value);
    int32 (*write)(uint8 lchip, uint8 mcu_id, uint32 addr, uint32 mask, uint32 value);
    int32 (*gen_intr)(uint8 lchip, uint8 mcu_id);
    int32 (*get_header_field)(void *p_header, uint8 field, uint32* p_val);
    int32 (*set_header_field)(void *p_header, uint8 field, uint32 val);
};
typedef struct sys_dmps_db_msg_handle_s sys_dmps_db_msg_handle_t;

///////////////////////////////////////////////////////////////////////////////
struct sys_dmps_db_cpumac_map_s
{
    uint16 lport;
    uint16 chan_id;
    uint16 is_network;
};
typedef struct sys_dmps_db_cpumac_map_s sys_dmps_db_cpumac_map_t;

struct sys_dmps_db_chan_info_s
{
    uint8  core_id;
    uint8  pp_id;
    uint8  dp_id;
    uint8  txqm_id;

    uint16 sub_chan_id;
    uint16 mac_client_id;

    uint32 speed_value;

    uint8  speed_mode;
    uint8  prio;
    uint16 chan_id;
};
typedef struct sys_dmps_db_chan_info_s sys_dmps_db_chan_info_t;

enum sys_dmps_db_type_e
{
    DMPS_DB_TYPE_PORT,      //DMPS_DB_PORT
    DMPS_DB_TYPE_MAC,       //DMPS_DB_MAC
    DMPS_DB_TYPE_PSD,       //DMPS_DB_PSD
    DMPS_DB_TYPE_LSD,       //DMPS_DB_LSD
    DMPS_DB_TYPE_PCS,       //DMPS_DB_PCS
    DMPS_DB_TYPE_CHAN,      //DMPS_DB_CHAN
    DMPS_DB_TYPE_CHAN_RX,   //DMPS_DB_CHAN_RX
    DMPS_DB_TYPE_BUTT
};
typedef enum sys_dmps_db_type_e sys_dmps_db_type_t;

struct sys_dmps_db_chan2lsd_map_s
{
    uint8  occupy_flag; //sys_chan_lport_occupy_flag_t
    uint16 logic_serdes_id;
    uint16 dport;
};
typedef struct sys_dmps_db_chan2lsd_map_s sys_dmps_db_chan2lsd_map_t;

enum sys_dmps_db_item_upt_flag_e
{
    DB_ITEM_IGNORE, /*Both index and property to skip updating of this item*/
    DB_ITEM_UPDATE, /*For property it means updating, for index it means update map node(delete,build,modify map node)*/
    DB_ITEM_UPT_BUTT
};
typedef enum sys_dmps_db_item_upt_flag_e sys_dmps_db_item_upt_flag_t;

enum sys_dmps_db_serdes_scale_e
{
    SYS_DMPS_DB_SERDES_SCALE_0 = 0,     /* 9260: 96*50G + 64*100G */
    SYS_DMPS_DB_SERDES_SCALE_1,         /* 9260: 128*100G */
    SYS_DMPS_DB_SERDES_SCALE_2,         /* 9260: 144*50G */
    SYS_DMPS_DB_SERDES_SCALE_3,         /* 9260: 96*100G + 64*50G */

    SYS_DMPS_DB_SERDES_SCALE_4 = 10,    /* 9280: 256*100G */
    SYS_DMPS_DB_SERDES_SCALE_5,         /* 9280: 256*50G */

    SYS_DMPS_DB_SERDES_SCALE_MAX,
};
typedef enum sys_dmps_db_serdes_scale_e sys_dmps_db_serdes_scale_t;

/*total 96 bytes*/
struct sys_dmps_db_upt_info_s
{
    uint32 upt_map                  :1;
    uint32 upt_port_idx             :1;
    uint32 upt_port_type            :1;
    uint32 upt_if_type              :1;
    uint32 upt_if_mode              :1;
    uint32 upt_fec_type             :1;
    uint32 upt_an_fec               :1;
    uint32 upt_dport_is_rsv         :1;
    uint32 upt_an_mode              :1;
    uint32 upt_mdio_map             :1;
    uint32 upt_phy_map              :1;
    uint32 upt_devno_map            :1;
    uint32 upt_bp_ability0          :1;
    uint32 upt_bp_ability1          :1;
    uint32 upt_np0_ability0         :1;
    uint32 upt_np0_ability1         :1;
    uint32 upt_np1_ability0         :1;
    uint32 upt_np1_ability1         :1;
    uint32 upt_an_en                :1;
    uint32 upt_old_an_stat          :1;
    uint32 upt_link_intr_en         :1;
    uint32 upt_link_status          :1;
    uint32 upt_unidir_en            :1;
    uint32 upt_rx_rst_hold          :1;
    uint32 upt_ctle_run             :1;
    uint32 upt_xpipe_en             :1;
    uint32 upt_speed_mode           :1;
    uint32 upt_chan_is_rsv          :1;
    uint32 upt_prio                 :1;
    uint32 upt_sub_chan             :1;
    uint32 upt_mac_client           :1;
    uint32 upt_core                 :1;

    uint32 upt_pp                   :1;
    uint32 upt_dp                   :1;
    uint32 upt_txqm                 :1;
    uint32 upt_rx_speed_mode        :1;
    uint32 upt_rx_chan_is_rsv       :1;
    uint32 upt_rx_prio              :1;
    uint32 upt_rx_sub_chan          :1;
    uint32 upt_rx_mac_client        :1;
    uint32 upt_rx_core              :1;
    uint32 upt_rx_pp                :1;
    uint32 upt_rx_dp                :1;
    uint32 upt_rx_txqm              :1;
    uint32 upt_mac_speed            :1;
    uint32 upt_mac_group            :1;
    uint32 upt_mac_idx              :1;
    uint32 upt_mac_en               :1;
    uint32 upt_pcs_idx              :1;
    uint32 upt_rx_rst_en            :1;
    uint32 upt_is_dyn               :1;
    uint32 upt_logic_lane           :1;
    uint32 upt_pcsl_idx             :1;
    uint32 upt_hss_id               :1;
    uint32 upt_rx_pol               :1;
    uint32 upt_tx_pol               :1;
    uint32 upt_support_speed        :1;
    uint32 upt_curr_speed           :1;
    uint32 upt_ocs                  :1;
    uint32 upt_physic_lane          :1;
    uint32 upt_pll_sel              :1;
    uint32 upt_rate_div             :1;
    uint32 upt_bit_width            :1;
    uint32 upt_is_an_first          :1;

    uint32 upt_link_fsm             :1;
    uint32 upt_link_mode            :1;
    uint32 upt_speed_value          :1;
    uint32 upt_rx_speed_value       :1;
    uint32 upt_rsv                  :28;

    /*previous index*/
    uint16 old_dport;           /* Used for update mapping */
    uint16 old_chan_id;         /* Used for update mapping */
    uint16 old_mac_id;          /* Used for update mapping */
    uint16 old_pcs_id;          /* Used for update mapping */
    uint16 old_physic_serdes;   /* Used for update mapping */
    uint16 old_logic_serdes;    /* Used for update mapping */
    uint16 old_chan_rx_id;      /* Used for update mapping */

    /*PORT DB*/     
    uint16 dport;                       /*DB INDEX*/
    uint8  port_idx;     /* [Arctic] Cpumac port idx */
    uint8  port_type;    /* refer to sys_dmps_lport_type_t */

    uint8  if_type;      /* refer to ctc_port_if_type_t */
    uint8  if_mode;     /*refer to ctc_chip_serdes_mode_t*/
    uint8  fec_type;    /*ctc_port_fec_type_t*/
    uint8  an_fec;      /* refer to ctc_port_fec_type_t */

    uint8  mdio_map;
    uint8  phy_map;
    uint8  devno_map;
    uint8  dport_is_rsv;

    uint8  an_mode;     /* refer to ctc_port_auto_neg_mode_t */
    uint8  dport_rsv0;
    uint16 dport_rsv1;

    uint32 an_en              :1;       /* AN  enable/disable */
    uint32 old_an_stat        :2;
    uint32 link_intr_en       :1;
    uint32 link_status        :1;
    uint32 unidir_en          :1;
    uint32 rx_rst_hold        :1;
    uint32 ctle_run           :1;
    uint32 xpipe_en           :2;
    uint32 is_an_first        :1;
    uint32 link_fsm           :4;
    uint32 link_mode          :2;
    uint32 rsv                :15;

    uint32 bp_ability0;

    uint32 bp_ability1;

    uint32 np0_ability0;

    uint32 np0_ability1;

    uint32 np1_ability0;

    uint32 np1_ability1;

    /*CHAN DB*/
    uint16 chan_id;                       /*DB INDEX*/
    uint8  speed_mode;   /* refer to ctc_port_speed_t */
    uint8  chan_is_rsv;

    uint16 sub_chan;
    uint16 mac_client;

    uint32 speed_value; /* xxx Mb/s */

    uint8  core;
    uint8  pp;
    uint8  dp;
    uint8  txqm;

    uint8  prio;
    uint8  chan_rsv0;
    uint16 chan_srv1;

    /*CHAN RX DB*/
    uint16 chan_rx_id;                     /*DB INDEX*/
    uint8  rx_speed_mode;   /* refer to ctc_port_speed_t */
    uint8  rx_chan_is_rsv;

    uint16 rx_sub_chan;
    uint16 rx_mac_client;

    uint32 rx_speed_value; /* xxx Mb/s */

    uint8  rx_core;
    uint8  rx_pp;
    uint8  rx_dp;
    uint8  rx_txqm;

    uint8  rx_prio;
    uint8  rx_chan_rsv0;
    uint16 rx_chan_srv1;

    /*MAC DB*/
    uint16 mac_id;                       /*DB INDEX*/
    uint8  mac_speed;
    uint8  mac_group;

    uint8  mac_idx;
    uint8  mac_en;
    /*PCS DB*/
    uint16 pcs_id;                       /*DB INDEX*/

    uint8  pcs_idx;
    uint8  rx_rst_en;
    /*Logical SerDes DB*/
    uint16 logic_serdes;                       /*DB INDEX*/

    uint8  logic_lane;  /*logic serdes idx in group*/
    uint8  pcsl_idx;    /*lane idx in a pcs port*/
    uint8  hss_id;
    uint8  lsd_rsv;

    /*Physical SerDes DB*/
    uint16 physic_serdes;                       /*DB INDEX*/
    uint8  rx_pol;  /*0:normal, 1:reverse*/
    uint8  tx_pol;  /*0:normal, 1:reverse*/

    uint8  ocs;  /*serdes over clock: ctc_chip_serdes_ocs_mode_t*/
    uint8  physic_lane; /*real serdes idx in group*/
    uint8  pll_sel;
    uint8  rate_div;

    uint8  bit_width;
    uint8  is_dyn;
    uint16 psd_rsv;

    uint32 support_speed;   /* sys_datapath_serdes_speed_t */

    uint32 curr_speed;
};
typedef struct sys_dmps_db_upt_info_s sys_dmps_db_upt_info_t;

#define DMPS_DB_SET_MAP_UPDATE(info) do {\
    info.upt_map = DB_ITEM_UPDATE;\
}while(0)

#define DMPS_DB_SET_MAP_INFO(info, type, value) do {\
    switch (type)\
    {\
        case DMPS_DB_DPORT:\
            info.dport = value;\
            break;\
        case DMPS_DB_CHAN_ID:\
            info.chan_id = value;\
            break;\
        case DMPS_DB_CHAN_RX_ID:\
            info.chan_rx_id = value;\
            break;\
        case DMPS_DB_MAC_ID:\
            info.mac_id = value;\
            break;\
        case DMPS_DB_PCS_ID:\
            info.pcs_id = value;\
            break;\
        case DMPS_DB_LOGIC_SERDES:\
            info.logic_serdes = value;\
            break;\
        case DMPS_DB_PHYSIC_SERDES:\
            info.physic_serdes = value;\
            break;\
        case DMPS_DB_OLD_DPORT:\
            info.old_dport = value;\
            break;\
        case DMPS_DB_OLD_CHAN_ID:\
            info.old_chan_id = value;\
            break;\
        case DMPS_DB_OLD_CHAN_RX_ID:\
            info.old_chan_rx_id = value;\
            break;\
        case DMPS_DB_OLD_MAC_ID:\
            info.old_mac_id = value;\
            break;\
        case DMPS_DB_OLD_PCS_ID:\
            info.old_pcs_id = value;\
            break;\
        case DMPS_DB_OLD_LOGIC_SERDES:\
            info.old_logic_serdes = value;\
            break;\
        case DMPS_DB_OLD_PHYSIC_SERDES:\
            info.old_physic_serdes = value;\
            break;\
        default:\
            break;\
    }\
}while(0)

#define DMPS_DB_SET_PROPERTY_INFO(info, property_type, value) do {\
    switch (property_type)\
    {\
        case DMPS_DB_PORT_IDX:\
            info.upt_port_idx = DB_ITEM_UPDATE;\
            info.port_idx     = (uint8) value;\
            break;\
        case DMPS_DB_PORT_TYPE:\
            info.upt_port_type = DB_ITEM_UPDATE;\
            info.port_type     = (uint8) value;\
            break;\
        case DMPS_DB_PORT_IF_TYPE:\
            info.upt_if_type = DB_ITEM_UPDATE;\
            info.if_type     = (uint8) value;\
            break;\
        case DMPS_DB_PORT_IF_MODE:\
            info.upt_if_mode = DB_ITEM_UPDATE;\
            info.if_mode     = (uint8) value;\
            break;\
        case DMPS_DB_PORT_FEC_TYPE:\
            info.upt_fec_type = DB_ITEM_UPDATE;\
            info.fec_type     = (uint8) value;\
            break;\
        case DMPS_DB_PORT_AN_FEC:\
            info.upt_an_fec = DB_ITEM_UPDATE;\
            info.an_fec     = (uint8) value;\
            break;\
        case DMPS_DB_PORT_MDIO_MAP:\
            info.upt_mdio_map = DB_ITEM_UPDATE;\
            info.mdio_map     = (uint8) value;\
            break;\
        case DMPS_DB_PORT_PHY_MAP:\
            info.upt_phy_map = DB_ITEM_UPDATE;\
            info.phy_map     = (uint8) value;\
            break;\
        case DMPS_DB_PORT_DEVNO_MAP:\
            info.upt_devno_map = DB_ITEM_UPDATE;\
            info.devno_map     = (uint8) value;\
            break;\
        case DMPS_DB_PORT_IS_RSV:\
            info.upt_dport_is_rsv = DB_ITEM_UPDATE;\
            info.dport_is_rsv     = (uint8) value;\
            break;\
        case DMPS_DB_PORT_AN_MODE:\
            info.upt_an_mode = DB_ITEM_UPDATE;\
            info.an_mode     = (uint8) value;\
            break;\
        case DMPS_DB_PORT_AN_EN:\
            info.upt_an_en = DB_ITEM_UPDATE;\
            info.an_en     = value ? 1 : 0;\
            break;\
        case DMPS_DB_PORT_OLD_CL73_STAT:\
            info.upt_old_an_stat = DB_ITEM_UPDATE;\
            info.old_an_stat     = value % 4;\
            break;\
        case DMPS_DB_PORT_LINK_INTR_EN:\
            info.upt_link_intr_en = DB_ITEM_UPDATE;\
            info.link_intr_en     = value ? 1 : 0;\
            break;\
        case DMPS_DB_PORT_LINK_STATUS:\
            info.upt_link_status = DB_ITEM_UPDATE;\
            info.link_status     = value ? 1 : 0;\
            break;\
        case DMPS_DB_PORT_UNIDIR_EN:\
            info.upt_unidir_en = DB_ITEM_UPDATE;\
            info.unidir_en     = value ? 1 : 0;\
            break;\
        case DMPS_DB_PORT_RX_RST_HOLD:\
            info.upt_rx_rst_hold = DB_ITEM_UPDATE;\
            info.rx_rst_hold     = value ? 1 : 0;\
            break;\
        case DMPS_DB_PORT_IS_CTLE_RUN:\
            info.upt_ctle_run = DB_ITEM_UPDATE;\
            info.ctle_run     = value ? 1 : 0;\
            break;\
        case DMPS_DB_PORT_XPIPE_EN:\
            info.upt_xpipe_en = DB_ITEM_UPDATE;\
            info.xpipe_en     = value % 4;\
            break;\
        case DMPS_DB_PORT_BP_ABILITY0:\
            info.upt_bp_ability0 = DB_ITEM_UPDATE;\
            info.bp_ability0     = (uint32)value;\
            break;\
        case DMPS_DB_PORT_BP_ABILITY1:\
            info.upt_bp_ability1 = DB_ITEM_UPDATE;\
            info.bp_ability1     = (uint32)value;\
            break;\
        case DMPS_DB_PORT_NP0_ABILITY0:\
            info.upt_np0_ability0 = DB_ITEM_UPDATE;\
            info.np0_ability0     = (uint32)value;\
            break;\
        case DMPS_DB_PORT_NP0_ABILITY1:\
            info.upt_np0_ability1 = DB_ITEM_UPDATE;\
            info.np0_ability1     = (uint32)value;\
            break;\
        case DMPS_DB_PORT_NP1_ABILITY0:\
            info.upt_np1_ability0 = DB_ITEM_UPDATE;\
            info.np1_ability0     = (uint32)value;\
            break;\
        case DMPS_DB_PORT_NP1_ABILITY1:\
            info.upt_np1_ability1 = DB_ITEM_UPDATE;\
            info.np1_ability1     = (uint32)value;\
            break;\
        case DMPS_DB_PORT_IS_AN_FIRST:\
            info.upt_is_an_first = DB_ITEM_UPDATE;\
            info.is_an_first     = value ? 1 : 0;\
            break;\
        case DMPS_DB_PORT_LINK_FSM:\
            info.upt_link_fsm = DB_ITEM_UPDATE;\
            info.link_fsm     = value % 16;\
            break;\
        case DMPS_DB_PORT_LINK_MODE:\
            info.upt_link_mode = DB_ITEM_UPDATE;\
            info.link_mode     = value % 4;\
            break;\
        case DMPS_DB_CHAN_SPEED_VALUE:\
            info.upt_speed_value = DB_ITEM_UPDATE;\
            info.speed_value     = (uint32) value;\
            break;\
        case DMPS_DB_CHAN_SPEED_MODE:\
            info.upt_speed_mode = DB_ITEM_UPDATE;\
            info.speed_mode     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_IS_RSV:\
            info.upt_chan_is_rsv = DB_ITEM_UPDATE;\
            info.chan_is_rsv     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_PRIO:\
            info.upt_prio = DB_ITEM_UPDATE;\
            info.prio     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_SUB_CHAN_ID:\
            info.upt_sub_chan = DB_ITEM_UPDATE;\
            info.sub_chan     = (uint16)value;\
            break;\
        case DMPS_DB_CHAN_MAC_CLIENT_ID:\
            info.upt_mac_client = DB_ITEM_UPDATE;\
            info.mac_client     = (uint16)value;\
            break;\
        case DMPS_DB_CHAN_CORE_ID:\
            info.upt_core = DB_ITEM_UPDATE;\
            info.core     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_PP_ID:\
            info.upt_pp = DB_ITEM_UPDATE;\
            info.pp     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_DP_ID:\
            info.upt_dp = DB_ITEM_UPDATE;\
            info.dp     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_TXQM_ID:\
            info.upt_txqm = DB_ITEM_UPDATE;\
            info.txqm     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_RX_SPEED_MODE:\
            info.upt_rx_speed_mode = DB_ITEM_UPDATE;\
            info.rx_speed_mode     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_RX_IS_RSV:\
            info.upt_rx_chan_is_rsv = DB_ITEM_UPDATE;\
            info.rx_chan_is_rsv     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_RX_PRIO:\
            info.upt_rx_prio   = DB_ITEM_UPDATE;\
            info.rx_prio       = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_RX_SUB_CHAN_ID:\
            info.upt_rx_sub_chan = DB_ITEM_UPDATE;\
            info.rx_sub_chan     = value;\
            break;\
        case DMPS_DB_CHAN_RX_MAC_CLIENT_ID:\
            info.upt_rx_mac_client = DB_ITEM_UPDATE;\
            info.rx_mac_client     = value;\
            break;\
        case DMPS_DB_CHAN_RX_CORE_ID:\
            info.upt_rx_core = DB_ITEM_UPDATE;\
            info.rx_core     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_RX_PP_ID:\
            info.upt_rx_pp = DB_ITEM_UPDATE;\
            info.rx_pp     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_RX_DP_ID:\
            info.upt_rx_dp = DB_ITEM_UPDATE;\
            info.rx_dp     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_RX_TXQM_ID:\
            info.upt_rx_txqm = DB_ITEM_UPDATE;\
            info.rx_txqm     = (uint8) value;\
            break;\
        case DMPS_DB_CHAN_RX_SPEED_VALUE:\
            info.upt_rx_speed_value = DB_ITEM_UPDATE;\
            info.rx_speed_value     = (uint32) value;\
            break;\
        case DMPS_DB_MAC_SPEED:\
            info.upt_mac_speed = DB_ITEM_UPDATE;\
            info.mac_speed     = (uint8) value;\
            break;\
        case DMPS_DB_MAC_GROUP_ID:\
            info.upt_mac_group = DB_ITEM_UPDATE;\
            info.mac_group     = (uint8) value;\
            break;\
        case DMPS_DB_MAC_IDX:\
            info.upt_mac_idx = DB_ITEM_UPDATE;\
            info.mac_idx     = (uint8) value;\
            break;\
        case DMPS_DB_MAC_EN:\
            info.upt_mac_en = DB_ITEM_UPDATE;\
            info.mac_en     = (uint8) value;\
            break;\
        case DMPS_DB_PCS_IDX:\
            info.upt_pcs_idx = DB_ITEM_UPDATE;\
            info.pcs_idx     = (uint8) value;\
            break;\
        case DMPS_DB_PCS_RX_RST_EN:\
            info.upt_rx_rst_en = DB_ITEM_UPDATE;\
            info.rx_rst_en     = (uint8) value;\
            break;\
        case DMPS_DB_PSD_IS_DYN:\
            info.upt_is_dyn = DB_ITEM_UPDATE;\
            info.is_dyn     = (uint8) value;\
            break;\
        case DMPS_DB_LSD_LANE_ID:\
            info.upt_logic_lane = DB_ITEM_UPDATE;\
            info.logic_lane     = (uint8) value;\
            break;\
        case DMPS_DB_LSD_PCSL_IDX:\
            info.upt_pcsl_idx = DB_ITEM_UPDATE;\
            info.pcsl_idx     = (uint8) value;\
            break;\
        case DMPS_DB_LSD_HSS_ID:\
            info.upt_hss_id = DB_ITEM_UPDATE;\
            info.hss_id     = (uint8) value;\
            break;\
        case DMPS_DB_PSD_RX_POLARITY:\
            info.upt_rx_pol = DB_ITEM_UPDATE;\
            info.rx_pol     = (uint8) value;\
            break;\
        case DMPS_DB_PSD_TX_POLARITY:\
            info.upt_tx_pol = DB_ITEM_UPDATE;\
            info.tx_pol     = (uint8) value;\
            break;\
        case DMPS_DB_PSD_OCS:\
            info.upt_ocs = DB_ITEM_UPDATE;\
            info.ocs     = (uint8) value;\
            break;\
        case DMPS_DB_PSD_LANE_ID:\
            info.upt_physic_lane = DB_ITEM_UPDATE;\
            info.physic_lane     = (uint8) value;\
            break;\
        case DMPS_DB_PSD_SUPPORT_SPEED:\
            info.upt_support_speed = DB_ITEM_UPDATE;\
            info.support_speed     = (uint32)value;\
            break;\
        case DMPS_DB_PSD_SPEED:\
            info.upt_curr_speed = DB_ITEM_UPDATE;\
            info.curr_speed     = (uint32)value;\
            break;\
        case DMPS_DB_PSD_PLL_SEL:\
            info.upt_pll_sel = DB_ITEM_UPDATE;\
            info.pll_sel     = (uint8) value;\
            break;\
        case DMPS_DB_PSD_RATE_DIV:\
            info.upt_rate_div = DB_ITEM_UPDATE;\
            info.rate_div     = (uint8) value;\
            break;\
        case DMPS_DB_PSD_BIT_WIDTH:\
            info.upt_bit_width = DB_ITEM_UPDATE;\
            info.bit_width     = (uint8) value;\
            break;\
        default:\
            break;\
    }\
}while(0)

#define DMPS_DB_SET_PROPERTY_UPDATE(info, property_type) do {\
    switch (property_type)\
    {\
        case DMPS_DB_PORT_IDX:\
            info.upt_port_idx = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_TYPE:\
            info.upt_port_type = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_IF_TYPE:\
            info.upt_if_type = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_IF_MODE:\
            info.upt_if_mode = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_FEC_TYPE:\
            info.upt_fec_type = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_AN_FEC:\
            info.upt_an_fec = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_MDIO_MAP:\
            info.upt_mdio_map = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_PHY_MAP:\
            info.upt_phy_map = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_DEVNO_MAP:\
            info.upt_devno_map = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_IS_RSV:\
            info.upt_dport_is_rsv = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_AN_MODE:\
            info.upt_an_mode = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_AN_EN:\
            info.upt_an_en = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_OLD_CL73_STAT:\
            info.upt_old_an_stat = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_LINK_INTR_EN:\
            info.upt_link_intr_en = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_LINK_STATUS:\
            info.upt_link_status = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_UNIDIR_EN:\
            info.upt_unidir_en = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_RX_RST_HOLD:\
            info.upt_rx_rst_hold = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_IS_CTLE_RUN:\
            info.upt_ctle_run = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_XPIPE_EN:\
            info.upt_xpipe_en = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_BP_ABILITY0:\
            info.upt_bp_ability0 = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_BP_ABILITY1:\
            info.upt_bp_ability1 = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_NP0_ABILITY0:\
            info.upt_np0_ability0 = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_NP0_ABILITY1:\
            info.upt_np0_ability1 = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_NP1_ABILITY0:\
            info.upt_np1_ability0 = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_NP1_ABILITY1:\
            info.upt_np1_ability1 = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_IS_AN_FIRST:\
            info.upt_is_an_first = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_LINK_FSM:\
            info.upt_link_fsm = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PORT_LINK_MODE:\
            info.upt_link_mode = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_SPEED_MODE:\
            info.upt_speed_mode = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_IS_RSV:\
            info.upt_chan_is_rsv = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_PRIO:\
            info.upt_prio = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_SUB_CHAN_ID:\
            info.upt_sub_chan = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_MAC_CLIENT_ID:\
            info.upt_mac_client = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_CORE_ID:\
            info.upt_core = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_PP_ID:\
            info.upt_pp = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_DP_ID:\
            info.upt_dp = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_TXQM_ID:\
            info.upt_txqm = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_SPEED_VALUE:\
            info.upt_speed_value = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_RX_SPEED_MODE:\
            info.upt_rx_speed_mode = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_RX_IS_RSV:\
            info.upt_rx_chan_is_rsv = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_RX_PRIO:\
            info.upt_rx_prio = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_RX_SUB_CHAN_ID:\
            info.upt_rx_sub_chan = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_RX_MAC_CLIENT_ID:\
            info.upt_rx_mac_client = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_RX_CORE_ID:\
            info.upt_rx_core = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_RX_PP_ID:\
            info.upt_rx_pp = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_RX_DP_ID:\
            info.upt_rx_dp = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_RX_TXQM_ID:\
            info.upt_rx_txqm = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_CHAN_RX_SPEED_VALUE:\
            info.upt_rx_speed_value = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_MAC_SPEED:\
            info.upt_mac_speed = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_MAC_GROUP_ID:\
            info.upt_mac_group = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_MAC_IDX:\
            info.upt_mac_idx = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_MAC_EN:\
            info.upt_mac_en = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PCS_IDX:\
            info.upt_pcs_idx = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PCS_RX_RST_EN:\
            info.upt_rx_rst_en = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PSD_IS_DYN:\
            info.upt_is_dyn = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_LSD_LANE_ID:\
            info.upt_logic_lane = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_LSD_PCSL_IDX:\
            info.upt_pcsl_idx = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_LSD_HSS_ID:\
            info.upt_hss_id = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PSD_RX_POLARITY:\
            info.upt_rx_pol = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PSD_TX_POLARITY:\
            info.upt_tx_pol = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PSD_OCS:\
            info.upt_ocs = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PSD_LANE_ID:\
            info.upt_physic_lane = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PSD_SUPPORT_SPEED:\
            info.upt_support_speed = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PSD_SPEED:\
            info.upt_curr_speed = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PSD_PLL_SEL:\
            info.upt_pll_sel = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PSD_RATE_DIV:\
            info.upt_rate_div = DB_ITEM_UPDATE;\
            break;\
        case DMPS_DB_PSD_BIT_WIDTH:\
            info.upt_bit_width = DB_ITEM_UPDATE;\
            break;\
        default:\
            break;\
    }\
}while(0)

#define DMPS_DB_GET_MAP_INFO(info, type, value) do {\
    switch (type)\
    {\
        case DMPS_DB_DPORT:\
            value = info.dport;\
            break;\
        case DMPS_DB_CHAN_ID:\
            value = info.chan_id;\
            break;\
        case DMPS_DB_CHAN_RX_ID:\
            value = info.chan_rx_id;\
            break;\
        case DMPS_DB_MAC_ID:\
            value = info.mac_id;\
            break;\
        case DMPS_DB_PCS_ID:\
            value = info.pcs_id;\
            break;\
        case DMPS_DB_LOGIC_SERDES:\
            value = info.logic_serdes;\
            break;\
        case DMPS_DB_PHYSIC_SERDES:\
            value = info.physic_serdes;\
            break;\
        default:\
            break;\
    }\
}while(0)

#define DMPS_DB_GET_PROPERTY_INFO(info, property_type, value) do {\
    switch (property_type)\
    {\
        case DMPS_DB_PORT_IDX:\
            value = info.port_idx;\
            break;\
        case DMPS_DB_PORT_TYPE:\
            value = info.port_type;\
            break;\
        case DMPS_DB_PORT_IF_TYPE:\
            value = info.if_type;\
            break;\
        case DMPS_DB_PORT_IF_MODE:\
            value = info.if_mode;\
            break;\
        case DMPS_DB_PORT_FEC_TYPE:\
            value = info.fec_type;\
            break;\
        case DMPS_DB_PORT_AN_FEC:\
            value = info.an_fec;\
            break;\
        case DMPS_DB_PORT_MDIO_MAP:\
            value = info.mdio_map;\
            break;\
        case DMPS_DB_PORT_PHY_MAP:\
            value = info.phy_map;\
            break;\
        case DMPS_DB_PORT_DEVNO_MAP:\
            value = info.devno_map;\
            break;\
        case DMPS_DB_PORT_IS_RSV:\
            value = info.dport_is_rsv;\
            break;\
        case DMPS_DB_PORT_AN_MODE:\
            value = info.an_mode;\
            break;\
        case DMPS_DB_PORT_AN_EN:\
            value = info.an_en;\
            break;\
        case DMPS_DB_PORT_OLD_CL73_STAT:\
            value = info.old_an_stat;\
            break;\
        case DMPS_DB_PORT_LINK_INTR_EN:\
            value = info.link_intr_en;\
            break;\
        case DMPS_DB_PORT_LINK_STATUS:\
            value = info.link_status;\
            break;\
        case DMPS_DB_PORT_UNIDIR_EN:\
            value = info.unidir_en;\
            break;\
        case DMPS_DB_PORT_RX_RST_HOLD:\
            value = info.rx_rst_hold;\
            break;\
        case DMPS_DB_PORT_IS_CTLE_RUN:\
            value = info.ctle_run;\
            break;\
        case DMPS_DB_PORT_XPIPE_EN:\
            value = info.xpipe_en;\
            break;\
        case DMPS_DB_PORT_BP_ABILITY0:\
            value = info.bp_ability0;\
            break;\
        case DMPS_DB_PORT_BP_ABILITY1:\
            value = info.bp_ability1;\
            break;\
        case DMPS_DB_PORT_NP0_ABILITY0:\
            value = info.np0_ability0;\
            break;\
        case DMPS_DB_PORT_NP0_ABILITY1:\
            value = info.np0_ability1;\
            break;\
        case DMPS_DB_PORT_NP1_ABILITY0:\
            value = info.np1_ability0;\
            break;\
        case DMPS_DB_PORT_NP1_ABILITY1:\
            value = info.np1_ability1;\
            break;\
        case DMPS_DB_PORT_IS_AN_FIRST:\
            value = info.is_an_first;\
            break;\
        case DMPS_DB_PORT_LINK_FSM:\
            value = info.link_fsm;\
            break;\
        case DMPS_DB_PORT_LINK_MODE:\
            value = info.link_mode;\
            break;\
        case DMPS_DB_CHAN_SPEED_MODE:\
            value = info.speed_mode;\
            break;\
        case DMPS_DB_CHAN_IS_RSV:\
            value = info.chan_is_rsv;\
            break;\
        case DMPS_DB_CHAN_PRIO:\
            value = info.prio;\
            break;\
        case DMPS_DB_CHAN_SUB_CHAN_ID:\
            value = info.sub_chan;\
            break;\
        case DMPS_DB_CHAN_MAC_CLIENT_ID:\
            value = info.mac_client;\
            break;\
        case DMPS_DB_CHAN_CORE_ID:\
            value = info.core;\
            break;\
        case DMPS_DB_CHAN_PP_ID:\
            value = info.pp;\
            break;\
        case DMPS_DB_CHAN_DP_ID:\
            value = info.dp;\
            break;\
        case DMPS_DB_CHAN_TXQM_ID:\
            value = info.txqm;\
            break;\
        case DMPS_DB_CHAN_SPEED_VALUE:\
            value = info.speed_value;\
            break;\
        case DMPS_DB_CHAN_RX_SPEED_MODE:\
            value = info.rx_speed_mode;\
            break;\
        case DMPS_DB_CHAN_RX_IS_RSV:\
            value = info.rx_chan_is_rsv;\
            break;\
        case DMPS_DB_CHAN_RX_PRIO:\
            value = info.rx_prio;\
            break;\
        case DMPS_DB_CHAN_RX_SUB_CHAN_ID:\
            value = info.rx_sub_chan;\
            break;\
        case DMPS_DB_CHAN_RX_MAC_CLIENT_ID:\
            value = info.rx_mac_client;\
            break;\
        case DMPS_DB_CHAN_RX_CORE_ID:\
            value = info.rx_core;\
            break;\
        case DMPS_DB_CHAN_RX_PP_ID:\
            value = info.rx_pp;\
            break;\
        case DMPS_DB_CHAN_RX_DP_ID:\
            value = info.rx_dp;\
            break;\
        case DMPS_DB_CHAN_RX_TXQM_ID:\
            value = info.rx_txqm;\
            break;\
        case DMPS_DB_CHAN_RX_SPEED_VALUE:\
            value = info.rx_speed_value;\
            break;\
        case DMPS_DB_MAC_SPEED:\
            value = info.mac_speed;\
            break;\
        case DMPS_DB_MAC_GROUP_ID:\
            value = info.mac_group;\
            break;\
        case DMPS_DB_MAC_IDX:\
            value = info.mac_idx;\
            break;\
        case DMPS_DB_MAC_EN:\
            value = info.mac_en;\
            break;\
        case DMPS_DB_PCS_IDX:\
            value = info.pcs_idx;\
            break;\
        case DMPS_DB_PCS_RX_RST_EN:\
            value = info.rx_rst_en;\
            break;\
        case DMPS_DB_PSD_IS_DYN:\
            value = info.is_dyn;\
            break;\
        case DMPS_DB_LSD_LANE_ID:\
            value = info.logic_lane;\
            break;\
        case DMPS_DB_LSD_PCSL_IDX:\
            value = info.pcsl_idx;\
            break;\
        case DMPS_DB_LSD_HSS_ID:\
            value = info.hss_id;\
            break;\
        case DMPS_DB_PSD_RX_POLARITY:\
            value = info.rx_pol;\
            break;\
        case DMPS_DB_PSD_TX_POLARITY:\
            value = info.tx_pol;\
            break;\
        case DMPS_DB_PSD_OCS:\
            value = info.ocs;\
            break;\
        case DMPS_DB_PSD_LANE_ID:\
            value = info.physic_lane;\
            break;\
        case DMPS_DB_PSD_SUPPORT_SPEED:\
            value = info.support_speed;\
            break;\
        case DMPS_DB_PSD_SPEED:\
            value = info.curr_speed;\
            break;\
        case DMPS_DB_PSD_PLL_SEL:\
            value = info.pll_sel;\
            break;\
        case DMPS_DB_PSD_RATE_DIV:\
            value = info.rate_div;\
            break;\
        case DMPS_DB_PSD_BIT_WIDTH:\
            value = info.bit_width;\
            break;\
        default:\
            break;\
    }\
}while(0)

#define SYS_USW_GET_SPEED_VALUE(p_speed_mode, p_fec_type, p_ocs, p_speed_value)   \
do {    \
    switch(p_speed_mode)   \
    {   \
        case SYS_PORT_SPEED_1G:     \
            p_speed_value = 1000; \
            break;  \
        case SYS_PORT_SPEED_100M:    \
            p_speed_value = 100; \
            break;  \
        case SYS_PORT_SPEED_10M:    \
            p_speed_value = 10; \
            break;  \
        case SYS_PORT_SPEED_2G5:    \
            p_speed_value = 2000; \
            break;  \
        case SYS_PORT_SPEED_5G:    \
            p_speed_value = 5000; \
            break;  \
        case SYS_PORT_SPEED_10G:    \
            if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
            {   \
                p_speed_value = 10000;   \
            }   \
            else if ((CTC_CHIP_SERDES_OCS_MODE_11_06G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_11_06G11 == p_ocs))  \
            {   \
                p_speed_value = 11061;   \
            }   \
            else if (CTC_CHIP_SERDES_OCS_MODE_12_12G == p_ocs)  \
            {   \
                p_speed_value = 12121;   \
            }   \
            else if ((CTC_CHIP_SERDES_OCS_MODE_12_58G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_12_58G12 == p_ocs))  \
            {   \
                p_speed_value = 12576;   \
            }   \
            else if (CTC_CHIP_SERDES_OCS_MODE_10_6G == p_ocs)  \
            {   \
                p_speed_value = 10606;   \
            }   \
            break;  \
        case SYS_PORT_SPEED_20G:    \
            p_speed_value = 20000; \
            break;  \
        case SYS_PORT_SPEED_40G:    \
            if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
            {   \
                p_speed_value = 40000;   \
            }   \
            else if ((CTC_CHIP_SERDES_OCS_MODE_11_06G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_11_06G11 == p_ocs))  \
            {   \
                p_speed_value = 44242;   \
            }   \
            else if (CTC_CHIP_SERDES_OCS_MODE_12_12G == p_ocs)  \
            {   \
                p_speed_value = 48485;   \
            }   \
            else if ((CTC_CHIP_SERDES_OCS_MODE_12_58G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_12_58G12 == p_ocs))  \
            {   \
                p_speed_value = 50303;   \
            }   \
            else if (CTC_CHIP_SERDES_OCS_MODE_10_6G == p_ocs)  \
            {   \
                p_speed_value = 42424;   \
            }   \
            break;  \
        case SYS_PORT_SPEED_25G:    \
            if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
            {   \
                p_speed_value = 25000;   \
            }   \
            else if (CTC_CHIP_SERDES_OCS_MODE_27_27G == p_ocs)  \
            {   \
                p_speed_value = 27273;   \
            }   \
            else if (CTC_CHIP_SERDES_OCS_MODE_26_52G == p_ocs)  \
            {   \
                p_speed_value = 26515;   \
            }   \
            else if (CTC_CHIP_SERDES_OCS_MODE_26_9G == p_ocs)  \
            {   \
                p_speed_value = 26939;   \
            }   \
            break;  \
        case SYS_PORT_SPEED_50G:    \
            if ((SYS_DMPS_FEC_TYPE_NONE == p_fec_type) || (SYS_DMPS_FEC_TYPE_RS528 == p_fec_type))  \
            {   \
                if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
                {   \
                    p_speed_value = 50000;   \
                }   \
                else if ((CTC_CHIP_SERDES_OCS_MODE_27_27G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_52_94G == p_ocs))  \
                {   \
                    p_speed_value = 54545;   \
                }   \
                else if (CTC_CHIP_SERDES_OCS_MODE_26_52G == p_ocs)  \
                {   \
                    p_speed_value = 53030;   \
                }   \
                else if (CTC_CHIP_SERDES_OCS_MODE_26_9G == p_ocs)  \
                {   \
                    p_speed_value = 53879;   \
                }   \
            }   \
            else if (SYS_DMPS_FEC_TYPE_RS544 == p_fec_type) \
            {   \
                if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
                {   \
                    p_speed_value = 50000;   \
                }   \
                else if ((CTC_CHIP_SERDES_OCS_MODE_27_27G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_52_94G == p_ocs))  \
                {   \
                    p_speed_value = 52941;   \
                }   \
                else if (CTC_CHIP_SERDES_OCS_MODE_26_52G == p_ocs)  \
                {   \
                    p_speed_value = 51471;   \
                }   \
                else if (CTC_CHIP_SERDES_OCS_MODE_26_9G == p_ocs)  \
                {   \
                    p_speed_value = 52294;   \
                }   \
            }   \
            else if (SYS_DMPS_FEC_TYPE_RS272 == p_fec_type) \
            {   \
                if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
                {   \
                    p_speed_value = 50000;   \
                }   \
                else if (CTC_CHIP_SERDES_OCS_MODE_52_94G == p_ocs)  \
                {   \
                    p_speed_value = 52941;   \
                }   \
            }   \
            break;  \
        case SYS_PORT_SPEED_100G:   \
            if ((SYS_DMPS_FEC_TYPE_NONE == p_fec_type) || (SYS_DMPS_FEC_TYPE_RS528 == p_fec_type))  \
            {   \
                if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
                {   \
                    p_speed_value = 100000;   \
                }   \
                else if ((CTC_CHIP_SERDES_OCS_MODE_27_27G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_52_94G == p_ocs))  \
                {   \
                    p_speed_value = 109091;   \
                }   \
                else if (CTC_CHIP_SERDES_OCS_MODE_26_52G == p_ocs)  \
                {   \
                    p_speed_value = 106061;   \
                }   \
                else if (CTC_CHIP_SERDES_OCS_MODE_26_9G == p_ocs)  \
                {   \
                    p_speed_value = 107758;   \
                }   \
            }   \
            else if (SYS_DMPS_FEC_TYPE_RS544 == p_fec_type) \
            {   \
                if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
                {   \
                    p_speed_value = 100000;   \
                }   \
                else if ((CTC_CHIP_SERDES_OCS_MODE_27_27G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_52_94G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_105_88G == p_ocs))  \
                {   \
                    p_speed_value = 105882;   \
                }   \
                else if (CTC_CHIP_SERDES_OCS_MODE_26_52G == p_ocs)  \
                {   \
                    p_speed_value = 102941;   \
                }   \
                else if (CTC_CHIP_SERDES_OCS_MODE_26_9G == p_ocs)  \
                {   \
                    p_speed_value = 104588;   \
                }   \
            }   \
            else if ((SYS_DMPS_FEC_TYPE_RS272 == p_fec_type) || (SYS_DMPS_FEC_TYPE_RS544INT == p_fec_type) || (SYS_DMPS_FEC_TYPE_RS272INT == p_fec_type))   \
            {   \
                if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
                {   \
                    p_speed_value = 100000;   \
                }   \
                else if ((CTC_CHIP_SERDES_OCS_MODE_52_94G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_105_88G == p_ocs)) \
                {   \
                    p_speed_value = 105882;   \
                }   \
            }   \
            break;  \
         case SYS_PORT_SPEED_200G:   \
            if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
            {   \
                p_speed_value = 200000;   \
            }   \
            else if ((CTC_CHIP_SERDES_OCS_MODE_52_94G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_105_88G == p_ocs)) \
            {   \
                p_speed_value = 211765;   \
            }   \
            break;  \
        case SYS_PORT_SPEED_400G:   \
            if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
            {   \
                p_speed_value = 400000;   \
            }   \
            else if ((CTC_CHIP_SERDES_OCS_MODE_52_94G == p_ocs) || (CTC_CHIP_SERDES_OCS_MODE_105_88G == p_ocs)) \
            {   \
                p_speed_value = 423529;   \
            }   \
            break;  \
        case SYS_PORT_SPEED_800G:   \
            if (CTC_CHIP_SERDES_OCS_MODE_NONE == p_ocs) \
            {   \
                p_speed_value = 800000;   \
            }   \
            else if (CTC_CHIP_SERDES_OCS_MODE_105_88G == p_ocs) \
            {   \
                p_speed_value = 847059;   \
            }   \
            break;  \
        case SYS_PORT_SPEED_300G:   \
            p_speed_value = 300000;  \
            break;  \
        default:\
            p_speed_value = 0;\
            break;\
    }\
} while(0)


#define SYS_DMPS_GET_PP_ID_PER_CORE(pp) ((0 == PP_NUM_PER_CORE) ? 0 : ((pp) % PP_NUM_PER_CORE))
#define SYS_DMPS_GET_CHIP_PP(core, pp_id) (PP_NUM_PER_CORE * (core) + (pp_id))
#define SYS_DMPS_GET_CORE_ID_BY_PP(pp) ((0 == PP_NUM_PER_CORE) ? 0 : ((pp) / PP_NUM_PER_CORE))

extern int32
sys_usw_dmps_db_get_single_relative_id(uint8 lchip, uint8 src_db, uint16 src_id, uint8 dst_db, uint16* p_dst_id);
extern int32
sys_usw_dmps_db_get_relative_id(uint8 lchip, uint8 src_db, uint16 src_id, uint8 dst_db,
                                uint8* p_dst_num, uint16* arr_dst_id);
extern int32 sys_usw_dmps_db_get_dport_relative_id(uint8 lchip, uint16 dport, uint8 dst_db, uint16* p_dst_id);

extern uint8 sys_usw_dmps_db_is_valid_id(uint8 lchip, uint8 db_type, uint16 db_id);

extern int32 sys_usw_dmps_db_is_usable_id(uint8 lchip, uint8 db_type, uint16 db_id);

extern uint8 sys_usw_dmps_db_is_lport_valid(uint8 lchip, uint16 lport);

extern int32
sys_usw_dmps_db_lport_2_dport(uint8 lchip, uint16 lport, uint16* p_dport);
extern int32
sys_usw_dmps_db_dport_2_lport(uint8 lchip, uint16 dport, uint16* p_lport);

extern int32 sys_usw_dmps_db_get_core_id_by_dport(uint8 lchip, uint16 dport, uint8* core_id);

extern int32 sys_usw_dmps_db_set_internal_prop(uint8 lchip, uint8 db_prop, uint32 id, void* p_value);

extern int32 sys_usw_dmps_db_get_internal_prop(uint8 lchip, uint8 db_prop, uint32 id, void* p_value);

extern int32
sys_usw_dmps_db_alloc_chan_by_dir(uint8 lchip, uint32* p_chan_id, uint8 dir_bmp);

extern int32
sys_usw_dmps_db_alloc_chan(uint8 lchip, uint32* p_chan_id);

extern int32
sys_usw_dmps_db_alloc_port(uint8 lchip, uint32* p_lport);

extern int32
sys_usw_dmps_db_assign_chan_by_dir(uint8 lchip, uint32 chan_id, uint8 dir_bmp);

extern int32
sys_usw_dmps_db_assign_chan(uint8 lchip, uint32 chan_id);

extern int32
sys_usw_dmps_db_assign_port(uint8 lchip, uint32 lport);

extern int32
sys_usw_dmps_db_free_chan_by_dir(uint8 lchip, uint32 chan_id, uint8 dir_bmp);

extern int32
sys_usw_dmps_db_free_chan(uint8 lchip, uint32 chan_id);

extern int32
sys_usw_dmps_db_free_port(uint8 lchip, uint32 p_lport);

extern int32
sys_usw_dmps_db_get_misc_chan_info(uint8 lchip, uint8 misc_chan_type, sys_port_api_misc_chan_info_t* p_misc_info);

extern int32
sys_usw_dmps_db_set_internal_port_info(uint8 lchip, sys_internal_port_info_t* p_port_info);

extern int32 sys_usw_dmps_db_set_port_info(uint8 lchip, sys_dmps_db_upt_info_t* p_upt_info);

extern int32 sys_usw_dmps_db_get_port_info(uint8 lchip, sys_dmps_db_upt_info_t* p_upt_info);

extern int32 sys_usw_dmps_db_get_chan_info(uint8 lchip, sys_dmps_db_chan_info_t* chan_info, uint8 dir_bmp);

extern int32 sys_usw_dmps_db_upt_info_init(uint8 lchip, sys_dmps_db_upt_info_t* p_upt_info);

extern int32
sys_usw_dmps_db_api_get_com_info(uint8 lchip, uint16 lport, uint8 index, sys_port_info_t* p_port_info);

extern int32
sys_usw_dmps_db_api_get_port_info(uint8 lchip, uint16 lport, sys_port_api_dmps_info_t* p_port_info);

extern int32
sys_usw_dmps_db_api_get_port_property(uint8 lchip, sys_dmps_port_info_t* port_info, sys_port_api_dmps_property_t port_prop, void *p_value);

extern uint16
sys_usw_dmps_db_api_get_lport_with_chan(uint8 lchip, uint8 dir_bmp, uint16 chan_id);

extern uint16
sys_usw_dmps_db_api_get_lport_with_subchan(uint8 lchip, uint8 dir_bmp, uint8 core, uint8 pp, uint8 dp, uint8 sub_chan);

extern uint16
sys_usw_dmps_db_api_get_lport_with_mac(uint8 lchip, uint16 mac_id);

extern int32
sys_usw_dmps_db_api_get_sub_chan_by_chan(uint8 lchip, uint8 dir_bmp, uint16 chan, uint16* sub_chan, uint8* pp_id, uint8* dp_id);

extern int32 sys_usw_dmps_db_get_lport_by_psd(uint8 lchip, uint16 psd, uint16 *lport);

extern int32 sys_usw_dmps_db_init(uint8 lchip);

extern int32 sys_usw_dmps_db_deinit(uint8 lchip);

extern int32 sys_usw_dmps_db_get_port_property(uint8 lchip, sys_dmps_port_info_t* port_info, uint8 port_prop, void *p_value);

extern int32
sys_usw_dmps_db_set_mac_en(uint8 lchip, uint16 lport, uint32 en);

extern int32
sys_usw_dmps_db_get_mac_en(uint8 lchip, uint16 lport, uint32* p_en);
    
extern int32
sys_usw_dmps_db_get_fec_type(uint8 lchip, uint16 lport, uint8* p_fec_type);

extern int32
sys_usw_dmps_db_set_fec_type(uint8 lchip, uint16 lport, uint8 fec_type);

extern int32
sys_usw_dmps_db_get_mac_id(uint8 lchip, uint16 lport, uint16* p_mac_id);

extern int32
sys_usw_dmps_db_get_pcs_idx(uint8 lchip, uint16 lport, uint8* p_pcs_idx);
    
extern int32
sys_usw_dmps_db_get_an_mode(uint8 lchip, uint16 lport, uint8* p_an_mode);

extern int32
sys_usw_dmps_db_set_an_mode(uint8 lchip, uint16 lport, uint8 an_mode);

extern int32
sys_usw_dmps_db_get_an_fec(uint8 lchip, uint16 lport, uint32* p_an_fec);

extern int32
sys_usw_dmps_db_set_an_fec(uint8 lchip, uint16 lport, uint32 an_fec);

extern int32
sys_usw_dmps_db_get_speed_mode(uint8 lchip, uint16 lport, uint8* p_speed_mode);

extern int32
sys_usw_dmps_db_set_speed_mode(uint8 lchip, uint16 lport, uint8 speed_mode);

extern int32
sys_usw_dmps_db_get_xpipe_en(uint8 lchip, uint16 lport, uint32* p_en);

extern int32
sys_usw_dmps_db_set_xpipe_en(uint8 lchip, uint16 lport, uint32 en);

extern int32
sys_usw_dmps_db_get_ifmode(uint8 lchip, uint16 lport, uint8* p_mode);

extern int32
sys_usw_dmps_db_set_ifmode(uint8 lchip, uint16 lport, uint8 mode);

extern uint16
sys_usw_dmps_db_get_lport_by_dport(uint8 lchip, uint16 dport);
uint16
sys_usw_dmps_db_get_dport_by_lport(uint8 lchip, uint16 lport);

extern int32
sys_usw_dmps_db_get_serdes_speed(uint8 lchip, uint16 psd, uint32* p_speed);

extern int32
sys_usw_dmps_db_set_serdes_speed(uint8 lchip, uint16 psd, uint32 speed);
    
extern int32
sys_usw_dmps_db_get_port_type(uint8 lchip, uint16 lport, uint8* p_port_type);

extern int32
sys_usw_dmps_db_set_port_type(uint8 lchip, uint16 lport, uint8 port_type);
    
extern int32
sys_usw_dmps_db_get_pcs_idx(uint8 lchip, uint16 pcs_id, uint8* p_pcs_idx);

extern int32
sys_usw_dmps_db_set_pcs_idx(uint8 lchip, uint16 pcs_id, uint8 pcs_idx);

extern int32
sys_usw_dmps_db_get_cl73_en(uint8 lchip, uint16 lport, uint32* p_an_en);

extern int32
sys_usw_dmps_db_set_cl73_en(uint8 lchip, uint16 lport, uint32 an_en);
    
extern int32
sys_usw_dmps_db_get_ifmode_by_psd(uint8 lchip, uint16 psd, uint8* p_mode);
    
extern int32
sys_usw_dmps_db_dump(uint8 lchip, sal_file_t fp, ctc_global_dump_db_t* p_dump_param);

extern int32
sys_usw_dmps_dump_db(uint8 lchip, sal_file_t p_f,ctc_global_dump_db_t* p_dump_param);

extern int32
sys_usw_dmps_wb_sync_master(uint8 lchip, uint32 app_id);

extern int32
sys_usw_dmps_wb_init(uint8 lchip);
extern int32 
sys_usw_dmps_wb_sync_master(uint8 lchip, uint32 app_id);
extern int32 
sys_usw_dmps_wb_restore_master(uint8 lchip);
extern int32
sys_usw_dmps_db_get_psd_by_lport(uint8 lchip, uint16 lport, uint16* psd, uint8* p_num);
extern int32
sys_usw_dmps_db_get_lsd_by_lport(uint8 lchip, uint16 lport, uint16* lsd, uint8* p_num);
extern int32
sys_usw_dmps_db_get_mac_group_valid(uint8 lchip, uint8 core_id, uint32* p_mac_group_valid);
extern int32
sys_usw_dmps_db_set_mac_group_valid(uint8 lchip, uint8 core_id, uint32 mac_group_valid);
extern int32
sys_usw_dmps_db_get_core_pll(uint8 lchip, uint16* p_core_pll, uint8 core_type);
extern int32
sys_usw_dmps_db_set_chan2lsd(uint8 lchip, uint8 core_id, uint16 chan_idx, uint8 occupy_flag, uint16 lsd, uint16 dport);
extern int32
sys_usw_dmps_db_get_chan2lsd(uint8 lchip, uint8 core_id, uint16 chan_idx, uint8* p_occupy_flag, uint16* p_lsd, uint16* p_dport);
extern int32
sys_usw_dmps_db_set_ext_lport_map(uint8 lchip, uint16 lport, uint16 dport);
extern int32
sys_usw_dmps_db_get_cpumac_dport(uint8 lchip, uint8 port_idx, uint16* p_dport);
extern int32
sys_usw_dmps_db_set_cpumac_dport(uint8 lchip, uint8 port_idx, uint16 dport);
extern int32
sys_usw_dmps_db_get_cpumac_map(uint8 lchip, uint8 port_idx, sys_dmps_db_cpumac_map_t* p_map);
extern int32
sys_usw_dmps_db_set_cpumac_map(uint8 lchip, uint8 port_idx, sys_dmps_db_cpumac_map_t* p_map);
extern int32
sys_usw_dmps_db_cpumac_get_lport_info_by_inner_idx(uint8 lchip, uint8 inner_idx, uint16* lport, uint8 *is_network);
extern int32
sys_usw_dmps_db_set_core_pll(uint8 lchip, uint16 core_pll);
extern int32
sys_usw_dmps_db_get_core_pp_dp_txqm_by_chan(uint8 lchip, uint16 chan_id, uint8* p_core_id, uint8* p_pp_id, uint8* p_dp_id, uint8* p_txqm_id, uint8 dir);
extern int32
sys_usw_dmps_db_get_serdes_ocs(uint8 lchip, uint16 psd, uint8* p_ocs);
extern int32
sys_usw_dmps_db_set_serdes_ocs(uint8 lchip, uint16 psd, uint8 ocs);
extern int32
sys_usw_dmps_db_get_glbcfg_from_db(uint8 lchip, ctc_datapath_global_cfg_t* p_glbcfg);
extern int32
sys_usw_dmps_db_get_link_fsm(uint8 lchip, uint16 lport, uint32* p_link_fsm);
extern int32
sys_usw_dmps_db_set_link_fsm(uint8 lchip, uint16 lport, uint32 link_fsm);
extern int32
sys_usw_dmps_db_get_link_mode(uint8 lchip, uint16 lport, uint32* p_link_mode);
extern int32
sys_usw_dmps_db_set_link_mode(uint8 lchip, uint16 lport, uint32 link_mode);
extern int32
sys_usw_dmps_db_get_an_en(uint8 lchip, uint16 lport, uint32* p_an_en);
extern int32
sys_usw_dmps_db_set_an_en(uint8 lchip, uint16 lport, uint32 an_en);
extern int32
sys_usw_dmps_db_get_link_mode_by_dport(uint8 lchip, uint16 dport, uint32* p_link_mode);
extern int32
sys_usw_dmps_db_set_link_mode_by_dport(uint8 lchip, uint16 dport, uint32 link_mode);
extern int32
sys_usw_dmps_db_get_bpe_full_mode(uint8 lchip, uint8* p_bpe_full);
extern int32
sys_usw_dmps_db_set_bpe_full_mode(uint8 lchip, uint8 bpe_full_mode);
extern int32
sys_usw_dmps_db_get_serdes_scale(uint8 lchip, uint8* p_serdes_scale);
extern int32
sys_usw_dmps_db_set_serdes_scale(uint8 lchip, uint8 p_serdes_scale);
extern void
sys_usw_dmps_db_print_ext_lport_map(uint8 lchip, uint32 sign);
extern uint8
sys_usw_dmps_db_is_exist_bpefull_port(uint8 lchip);
extern uint16
sys_usw_dmps_db_get_dport_by_lport_raw(uint8 lchip, uint16 lport);
extern int32
sys_usw_dmps_db_get_psd_polarity(uint8 lchip, uint16 psd, uint8* p_tx_pol, uint8* p_rx_pol);
extern int32
sys_usw_dmps_db_set_psd_polarity(uint8 lchip, uint16 psd, uint8 dir, uint8 pol);
extern int32
sys_usw_dmps_db_get_psd_by_dport(uint8 lchip, uint16 dport, uint16* psd, uint8* p_num);
extern int32
sys_usw_dmps_db_get_psd_data_width(uint8 lchip, uint16 psd, uint8* p_data_width);
extern int32
sys_usw_dmps_db_set_psd_data_width(uint8 lchip, uint16 psd, uint8 data_width);
extern int32
sys_usw_dmps_db_get_psd_rate_div(uint8 lchip, uint16 psd, uint8* p_rate_div);
extern int32
sys_usw_dmps_db_set_psd_rate_div(uint8 lchip, uint16 psd, uint8 rate_div);
extern int32
sys_usw_dmps_db_get_interface_mode(uint8 lchip, uint16 lport, ctc_port_if_mode_t* if_mode);
extern int32
sys_usw_dmps_db_get_chan_by_info(uint8 lchip, uint8 p_core_id, uint8 p_pp_id, uint8 p_dp_id, uint16 index_in_dp, uint16* p_chan_id);
extern uint16
sys_usw_dmps_db_get_lport_with_chan(uint8 lchip, uint8 dir, uint16 chan_id);
extern int32 
sys_usw_dmps_db_set_xpipe_alloc(uint8 lchip, uint8 xpipe_alloc);
extern int32 
sys_usw_dmps_db_get_xpipe_alloc(uint8 lchip, uint8* xpipe_alloc);
extern int32
sys_usw_dmps_db_get_msg_handle(uint8 lchip, sys_dmps_db_msg_handle_t **pp_handle);
extern int32
sys_usw_dmps_db_set_msg_handle(uint8 lchip, sys_dmps_db_msg_handle_t *p_handle);
extern int32
sys_usw_dmps_db_set_msg_registers_tab(uint8 lchip, uint32 msg_type, uint8 priority, uint8 data_size, void* recv_cb);
extern uint16
sys_usw_dmps_db_get_lport_with_mac(uint8 lchip, uint16 mac_id);
#ifdef __cplusplus
}
#endif

#endif

